
describe('persona.guardar', function() {

    it('con ajax ok retorna yay', function() {
        var responseData = 'yay';
        var persona;
        var callbackOk = jasmine.createSpy();
        var callbackError = jasmine.createSpy();

        registerFakeAjax({
            url: '/persona',
            type: 'post',
            successData: responseData
        });
        dosideas.service.persona.guardar(persona,callbackOk,callbackError);
        expect(callbackOk).toHaveBeenCalledWith(responseData);
    });

    it('con ajax con error retorna error', function() {
        var persona;
        var callbackOk = jasmine.createSpy();
        var callbackError = jasmine.createSpy();
        var esperado = {
            responseText : 'fallo'
        };

        registerFakeAjax({
            url: '/persona',
            type: 'post',
            errorMessage: 'fallo'
        });
        dosideas.service.persona.guardar(persona,callbackOk,callbackError);
        expect(callbackError).toHaveBeenCalledWith(esperado);
    });
});

describe("persona.buscarPorId",function(){
    it("con id existente",function(){
        var persona = {
            "id":25,
            "nombre":"pepe",
            "apellido":"gonzalez"
        };
        var callbackOk = jasmine.createSpy();
        var callbackError = jasmine.createSpy();
        
        registerFakeAjax({
            url: '/persona/25',
            type: 'get',
            responseData: persona,
            success: callbackOk
        }); 
        
        dosideas.service.persona.buscar(25,callbackOk,callbackError);
        expect(callbackOk).toHaveBeenCalled();
    }); 
});